﻿Array.prototype.Add = function(obj)
{
    this.push(obj);
};

Array.prototype.Remove = function(obj)
{
    for(var i = 0; i < this.length; i++)
    {
        if(this[i] == obj)
        {
            this.splice(i, 1);
            return;
        }
    }
};

Array.prototype.Clear = function()
{
    this.length = 0;
};

Array.prototype.CallForEach = function(delegate)
{
    for(var i = 0; i < this.length; i++) { delegate(this[i]); }
};

Array.prototype.CallForEachReturnWhenNotNull = function(delegate)
{
    var testValue;
    for(var i = 0; i < this.length; i++) { if(testValue = delegate(this[i])) return testValue; }
    return null;
};

Array.prototype.AddRange = function(values)
{
    var thisInstance = this;
    values.CallForEach(function(value){thisInstance.Add(value);});
};

Array.prototype.Contains = function(obj)
{
    var found = false;
    this.CallForEach
    (
        function(element) { if(element==obj) found=true; }
    );
    return found;
};

Array.prototype.Insert = function(position, obj)
{
    this.splice(position, 0, obj);
}
